package com.ticket.system.service.impl;

import java.util.List;
import java.util.Map;

import com.ticket.common.core.domain.model.LoginUser;
import com.ticket.common.utils.DateUtils;
import com.ticket.system.service.ITYanchuPointsRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ticket.system.mapper.YanchuEvaluateMapper;
import com.ticket.system.domain.YanchuEvaluate;
import com.ticket.system.service.IYanchuEvaluateService;

import static com.ticket.common.utils.PageUtils.startPage;

/**
 * 演出评价Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-03-15
 */
@Service
public class YanchuEvaluateServiceImpl implements IYanchuEvaluateService 
{
    @Autowired
    private YanchuEvaluateMapper yanchuEvaluateMapper;
    @Autowired
    private ITYanchuPointsRuleService itYanchuPointsRuleService;

    /**
     * 查询演出评价
     * 
     * @param id 演出评价主键
     * @return 演出评价
     */
    @Override
    public YanchuEvaluate selectYanchuEvaluateById(Long id)
    {
        return yanchuEvaluateMapper.selectYanchuEvaluateById(id);
    }

    /**
     * 查询演出评价列表
     * 
     * @param yanchuEvaluate 演出评价
     * @return 演出评价
     */
    @Override
    public List<YanchuEvaluate> selectYanchuEvaluateList(YanchuEvaluate yanchuEvaluate)
    {
        return yanchuEvaluateMapper.selectYanchuEvaluateList(yanchuEvaluate);
    }

    /**
     * 新增演出评价
     * 
     * @param yanchuEvaluate 演出评价
     * @return 结果
     */
    @Override
    public int insertYanchuEvaluate(YanchuEvaluate yanchuEvaluate)
    {
        yanchuEvaluate.setCreateTime(DateUtils.getNowDate());
        yanchuEvaluate.setUpdateTime(DateUtils.getNowDate());
        int i = yanchuEvaluateMapper.insertYanchuEvaluate(yanchuEvaluate);
        if(i > 0){
            itYanchuPointsRuleService.addPoints(3,null,yanchuEvaluate.getCreator());
        }
        return i;
    }

    /**
     * 修改演出评价
     * 
     * @param yanchuEvaluate 演出评价
     * @return 结果
     */
    @Override
    public int updateYanchuEvaluate(YanchuEvaluate yanchuEvaluate)
    {
        yanchuEvaluate.setUpdateTime(DateUtils.getNowDate());
        yanchuEvaluate.setIsExcellent(1);
        yanchuEvaluate.setIsShow(1);
        return yanchuEvaluateMapper.updateYanchuEvaluate(yanchuEvaluate);
    }

    /**
     * 批量删除演出评价
     * 
     * @param ids 需要删除的演出评价主键
     * @return 结果
     */
    @Override
    public int deleteYanchuEvaluateByIds(Long[] ids)
    {
        return yanchuEvaluateMapper.deleteYanchuEvaluateByIds(ids);
    }

    /**
     * 删除演出评价信息
     * 
     * @param id 演出评价主键
     * @return 结果
     */
    @Override
    public int deleteYanchuEvaluateById(Long id)
    {
        return yanchuEvaluateMapper.deleteYanchuEvaluateById(id);
    }

    @Override
    public List<Map> getEvaluatePerformById(Long performId, LoginUser loginUser) {
        List<Map> evaluateList = yanchuEvaluateMapper.selectEvaluatePerformById(performId);
        return evaluateList;
    }

    @Override
    public int updateExcellent(String ids, Integer isExcellent) {
        String[] evaluateIds = ids.split(",");
        return yanchuEvaluateMapper.updateExcellent(evaluateIds, isExcellent);
    }

    @Override
    public YanchuEvaluate selectEvaluateByUserId(Long userId, Long performId) {
        return yanchuEvaluateMapper.selectEvaluateByUserId(userId,performId);
    }
}
